home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / gs24src.zip / GS_LEV2.PS < prev    next >
Text File  |  1992-02-16  |  8KB  |  242 lines

  1. %    Copyright (C) 1990, 1991 Aladdin Enterprises.  All rights reserved.
  2. %    Distributed by Free Software Foundation, Inc.
  3. %
  4. % This file is part of Ghostscript.
  5. %
  6. % Ghostscript is distributed in the hope that it will be useful, but
  7. % WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  8. % to anyone for the consequences of using it or for whether it serves any
  9. % particular purpose or works at all, unless he says so in writing.  Refer
  10. % to the Ghostscript General Public License for full details.
  11. %
  12. % Everyone is granted permission to copy, modify and redistribute
  13. % Ghostscript, but only under the conditions described in the Ghostscript
  14. % General Public License.  A copy of this license is supposed to have been
  15. % given to you along with Ghostscript so you can know your rights and
  16. % responsibilities.  It should be in a file named COPYING.  Among other
  17. % things, the copyright notice and this notice must be preserved on all
  18. % copies.
  19.  
  20. % Initialization file for Ghostscript Level 2 functions.
  21. % When this is run, systemdict is still writable.
  22.  
  23. % ------ Dictionaries ------ %
  24.  
  25. (<<) cvn /mark load def
  26. (>>) cvn /dicttomark load odef
  27.  
  28. % ------ Painting ------ %
  29.  
  30. % A straightforward definition of execform that doesn't actually
  31. % do any caching.
  32. /execform
  33.     { dup /Implementation known not
  34.        { dup /FormType get 1 ne { /rangecheck signalerror } if
  35.          dup /Implementation null put readonly } if
  36.       gsave dup /Matrix get concat
  37.       dup /BBox get aload pop
  38.       exch 3 index sub exch 2 index sub rectclip
  39.       dup /PaintProc get exec
  40.       grestore
  41.     } bind def
  42.  
  43. % ------ Resources ------ %
  44.  
  45. % Currently, we don't implement resource unloading or global/local
  46. % instance sets, and resourceforall only enumerates loaded instances.
  47. % The standard implementation of resource categories is
  48. % simply to have another entry in the resource dictionary, called Instances,
  49. % that keeps track of all the instances.
  50.  
  51. % Note that the dictionary that defines a resource category is stored
  52. % in global memory.  The PostScript manual says that each category must
  53. % manage global and local instances separately.  However, objects in
  54. % global memory can't reference objects in local memory.  This means
  55. % that the resource category dictionary, which would otherwise be the
  56. % obvious place to keep track of the instances, can't be used to keep
  57. % track of local instances.  Instead, there must be a parallel
  58. % structure in local memory for each resource category.  Needless to
  59. % say, we haven't implemented this yet.
  60.  
  61. % Define the Category category, except for most of the procedures.
  62. % The dictionary we're about to create will become the Category
  63. % category definition dictionary.
  64.  
  65. 10 dict begin
  66. /Category /Category def
  67. /CheckResource
  68.     { true
  69.        { /DefineResource /FindResource /ResourceForAll /ResourceStatus
  70.          /UndefineResource }
  71.        { 2 index exch known and }
  72.       forall exch pop } bind def
  73. /DefineResource
  74.     { dup CheckResource
  75.        { dup /Category 3 index put   Instances 3 1 roll put }
  76.        { /typecheck signalerror }
  77.       ifelse } bind def
  78. /FindResource        % temporary
  79.     { Instances exch get } bind def
  80. /Instances 25 dict def
  81. /InstanceType /dicttype def
  82.  
  83. Instances /Category currentdict put
  84. Instances end begin    % so we can name the Category definition
  85.  
  86. % Define the resource operators.
  87.  
  88. mark
  89. /defineresource
  90.     { /Category findresource dup begin
  91.       /InstanceType known
  92.        { dup type InstanceType ne
  93.          { dup type /packedarraytype eq InstanceType /arraytype eq and
  94.             not { /typecheck signalerror } if } if } if
  95.       DefineResource end
  96.     }
  97. /findresource
  98.     { dup /Category eq
  99.        { pop //Category } { /Category findresource } ifelse
  100.       begin FindResource end }
  101. /resourceforall
  102.     { /Category findresource begin ResourceForAll end }
  103. /resourcestatus
  104.     { /Category findresource begin ResourceStatus end }
  105. /undefineresource
  106.     { /Category findresource begin UndefineResource end }
  107. end        % Instances
  108. counttomark 2 idiv { bind def } repeat pop
  109.  
  110. % Define the Generic category.
  111.  
  112. 12 dict dup begin
  113. /Instances 0 dict def
  114. /CheckResource        % not a standard entry
  115.     { pop true } def
  116. /DefineResource
  117.     { dup CheckResource
  118.        { Instances 3 1 roll put }
  119.        { /typecheck signalerror }
  120.       ifelse
  121.     } bind def
  122. /FindResource
  123.     { dup ResourceStatus
  124.        { pop 1 gt { dup ResourceFile run } if
  125.          Instances exch get }
  126.        { /undefinedresource signalerror }
  127.       ifelse } bind def
  128. /ResourceFile        % not a standard entry
  129.     { currentdict /ResourceFileName get 100 string exch exec
  130.       (r) file } bind def
  131. /ResourceForAll
  132.     { % We construct a new procedure so we don't have to use
  133.       % static resources to hold the iteration state.
  134.       3 1 roll   cvlit 3 1 roll   cvlit 3 1 roll
  135.       { % Stack contains: key, instance, template, proc, scratch
  136.         4 index 3 index stringmatch
  137.          { 4 index type dup /stringtype eq exch /nametype eq or
  138.             { 4 index exch cvs exch 5 2 roll pop pop pop }
  139.         { pop exch pop exch pop }
  140.            ifelse exec }
  141.          { 5 { pop } repeat }
  142.         ifelse
  143.       } /exec cvx 5 packedarray cvx
  144.       Instances exch forall } bind def
  145. /ResourceStatus
  146.     { dup Instances exch known
  147.        { pop 1 0 true }
  148.        { mark exch { ResourceFile } stopped
  149.           { cleartomark false } { closefile cleartomark 0 true }
  150.          ifelse
  151.        } ifelse
  152.     } bind def
  153. /UndefineResource
  154.     { Instances exch undef } bind def
  155. end
  156. /Generic exch /Category defineresource
  157.  
  158. % Fill in the rest of the Category category.
  159. /Category /Category findresource dup
  160. /Generic /Category findresource begin
  161.  { /FindResource /ResourceStatus /ResourceForAll }
  162.  { dup load put dup } forall
  163. pop pop end
  164.  
  165. % Define the fixed categories.
  166.  
  167. 7 dict begin        % 5 procedures, Category, Instances
  168. /DefineResource
  169.     { /invalidaccess signalerror } bind def
  170. /FindResource
  171.     { Instances exch get } bind def
  172. /ResourceForAll
  173.     /Generic /Category findresource /ResourceForAll get def
  174. /ResourceStatus
  175.     { Instances exch known { 0 0 true } { false } ifelse } bind def
  176. /UndefineResource
  177.     { /invalidaccess signalerror } bind def
  178.  
  179. mark
  180.     % Things other than types
  181.  /ColorSpaceFamily {/DeviceRGB /DeviceGray}
  182.  /Emulator {}
  183.  /Filter
  184.    [ .filterdict { pop } forall ]
  185.  /IODevice {(%os%)}
  186.     % Types
  187.  /ColorRenderingType {}
  188.  /FMapType {2 3 4 5 6 7 8}
  189.  /FontType {1 3}
  190.  /FormType {1}
  191.  /HalftoneType {}
  192.  /ImageType {}
  193.  /PatternType {}
  194. counttomark 2 idiv
  195.  { currentdict dup maxlength dict copy begin
  196.    dup length dict dup begin exch { dup def } forall end readonly
  197.    /Instances exch def
  198.    currentdict /Category defineresource
  199.    currentdict end readonly pop
  200.  } repeat pop end
  201.  
  202. % Define the other built-in categories.
  203.  
  204. mark
  205.   /ColorRendering /dicttype /ColorSpace /arraytype /Encoding /arraytype
  206.   /Font /dicttype /Form /dicttype /Halftone /dicttype /Pattern /dicttype
  207.   /ProcSet /dicttype
  208. counttomark 2 idiv
  209.  { /Generic /Category findresource dup maxlength dict copy begin
  210.    /InstanceType exch def
  211.    /Instances 10 dict def
  212.    currentdict end /Category defineresource
  213.  } repeat pop
  214.  
  215. % Complete the Encoding category.
  216.  
  217. /findencoding
  218.     { /Encoding findresource } bind def
  219. /ISOLatin1Encoding ISOLatin1Encoding /Encoding defineresource
  220. /StandardEncoding StandardEncoding /Encoding defineresource
  221. /SymbolEncoding SymbolEncoding /Encoding defineresource
  222.  
  223. % Complete the Font category.
  224. % THIS IMPLEMENTATION IS VERY TENTATIVE.
  225.  
  226. /Font /Category findresource begin
  227. /olddefinefont /definefont load def
  228. /oldfindfont /findfont load def
  229. /DefineResource
  230.     { 2 copy olddefinefont exch 2 copy
  231.       Instances 3 1 roll put exch pop } bind def
  232. /FindResource
  233.     { oldfindfont } bind def
  234. end
  235.  
  236. /definefont
  237.     { /Font defineresource } bind def
  238. /findfont
  239.     { /Font findresource } bind def
  240. /undefinefont
  241.     { /Font undefineresource } bind def
  242.